using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Auth;

namespace WebApplication1.Controllers;

[ApiController]
[Route("api/[controller]/[action]")]
public class AccountController : ControllerBase
{
    private readonly JWTHelp _jwtHelper;
    public AccountController(JWTHelp jwtHelper)
    {
        _jwtHelper = jwtHelper;
    }
    
    [HttpGet]
    public ActionResult<string> GetToken()
    {
        return _jwtHelper.CreateToken();
    }

    [Authorize(Policy = "Admin")]
    [HttpGet]
    public ActionResult<string> GetTest()
    {
        return "Test Authorize";
    }
    [HttpGet]
    [Authorize(Policy="AdminRequireMentWds")]
    public ActionResult<string> GetWDS()
    {
        return "WDSS";
    }
    
    [Authorize]
    [HttpPost]
    public ActionResult<string> RefreshToken()
    {
        var token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", "");
        return _jwtHelper.RefreshToken(token);
    }
}